package com.deer.wms.api.configurer;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * Swagger 配置文件
 * <p>
 * Created by wei on 2021/8.
 */
@EnableKnife4j
@Configuration
@EnableOpenApi
public class ApiSwaggerConfigurer extends WebMvcConfigurerAdapter {

    /**
     * 注册swagger-ui.html
     *
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        /*registry.addResourceHandler("/webjars*")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");*/
    }

    @Bean
    public Docket createCompanyRestApi() {

        return new Docket(DocumentationType.OAS_30).groupName("租户管理")
                .apiInfo(apiInfo("系统管理服务提供的 RestFul APIs"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.deer.wms.company"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createSystemManageRestApi() {
        return new Docket(DocumentationType.OAS_30).groupName("系统管理")
                .apiInfo(apiInfo("系统管理服务提供的 RestFul APIs"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.deer.wms.system.manage"))
                .paths(PathSelectors.any())
                .build();
    }


    @Bean
    public Docket createReviewManageRestApi() {
        return new Docket(DocumentationType.OAS_30).groupName("审核管理")
                .apiInfo(apiInfo("审核管理服务提供的 RestFul APIs"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.deer.wms.review.manage"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createBaseSystemConstantRestApi() {
        return new Docket(DocumentationType.OAS_30).groupName("基本信息")
                .apiInfo(apiInfo("审核管理服务提供的 RestFul APIs"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.deer.wms.base.system"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createQuartzConstantRestApi() {
        return new Docket(DocumentationType.OAS_30).groupName("定时器")
                .apiInfo(apiInfo("定时器服务提供的 RestFul APIs"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.deer.wms.quartz"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createBusinessConstantRestApi() {
        return new Docket(DocumentationType.OAS_30).groupName("业务规则")
                .apiInfo(apiInfo("定时器服务提供的 RestFul APIs"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.deer.wms.busine.tactic"))
                .paths(PathSelectors.any())
                .build();
    }    @Bean
    public Docket instockApi() {
        return new Docket(DocumentationType.OAS_30).groupName("转移单")
                .apiInfo(apiInfo("定时器服务提供的 RestFul APIs"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.deer.wms.instock"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createInventoryConstantRestApi() {
        return new Docket(DocumentationType.OAS_30).groupName("库存事务")
                .apiInfo(apiInfo("定时器服务提供的 RestFul APIs"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.deer.wms.inventory"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createAsnManageRestApi() {
        return new Docket(DocumentationType.OAS_30).groupName("ASN")
                .apiInfo(apiInfo("系统管理服务提供的 RestFul APIs"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.deer.wms.ASN.manage"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket createWareTaskRestApi() {
        return new Docket(DocumentationType.OAS_30).groupName("仓库业务")
                .apiInfo(apiInfo("系统管理服务提供的 RestFul APIs"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.deer.wms.ware.task"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket kuaidiniaoApi() {
        return new Docket(DocumentationType.OAS_30).groupName("快递鸟")
                .apiInfo(apiInfo("快递鸟提供的 RestFul APIs"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.deer.wms.kuaidiniao"))
                .paths(PathSelectors.any())
                .build();
    }


    @Bean
    public Docket UreportApi() {
        return new Docket(DocumentationType.OAS_30).groupName("Ureport")
                .apiInfo(apiInfo("Ureport提供的 RestFul APIs"))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.deer.wms.ureport"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(String description) {// 创建API的基本信息，这些信息会在Swagger UI中进行显示
        return new ApiInfoBuilder()
                .title("使用 Swagger3 构建的 RestFul APIs")// API 标题
                .description(description)// API描述
                .contact(new Contact("EpicHust", "", "wei.luo@epichust.com")) //联系人
                .version("1.0")// 版本号
                .build();
    }
}
